/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2025-04-12
 * Time: 21:27
 */
class Counter {
    private int count;
    private static int amount;
    private static int sum;
    public synchronized void add() {
        count++;
    }

    public int getCount() {
        return count;
    }
    public static int getAmount() {
        return amount;
    }
    public static int getSum() {
        return sum;
    }
    public synchronized static void func() {
        synchronized (Counter.class) {
            amount++;
        }
    }
    public synchronized static void func2() {
        sum++;
    }
}
public class Demo26 {
    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 500000; i++) {
                counter.add();
                Counter.func();
                Counter.func2();
            }
            System.out.println("t1线程结束");
        });
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 500000; i++) {
                counter.add();
                Counter.func();
                Counter.func2();
            }
            System.out.println("t2线程结束");
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(counter.getCount());
        System.out.println(Counter.getAmount());
        System.out.println(Counter.getSum());
    }
}
